package cn.wolfcode.p2p.controller;

import cn.wolfcode.p2p.base.anno.NeedLogin;
import cn.wolfcode.p2p.base.domain.LoginInfo;
import cn.wolfcode.p2p.base.service.IAccountService;
import cn.wolfcode.p2p.base.service.IUserInfoService;
import cn.wolfcode.p2p.hosting.service.IHostingService;
import cn.wolfcode.p2p.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 个人信息控制器
 */
@Controller
public class PersonalController {

    @Autowired
    private IUserInfoService userInfoService;
    @Autowired
    private IAccountService accountService;
    @Autowired
    private IHostingService hostingService;

    @RequestMapping("personal")
    @NeedLogin
    public String getById(Model model) {
        LoginInfo currentUser = UserContext.getCurrentUser();
        model.addAttribute("userInfo", userInfoService.getById(UserContext.getCurrentUser().getId()));
        model.addAttribute("account",accountService.getById(UserContext.getCurrentUser().getId()));
        return "personal/personal";
    }

    /**
     * 进入托管账户个人中心
     */
    @RequestMapping("hostingPersonal")
    public String hostingPersonal(){
        String url = hostingService.hostingPersonal(UserContext.getCurrentUser());
        return "redirect:"+url;
    }
    /**
     * 设置托管账户的支付密码
     */
    @RequestMapping("hostingSetPayPassword")
    public String hostingSetPayPassword(){
        String url = hostingService.hostingSetPayPassword(UserContext.getCurrentUser());
        return "redirect:"+url;
    }

    /**
     * 设置托管支付密码回调
     */
 /*   @RequestMapping("callbackSetPayPassword")
    @ResponseBody
    public String callbackSetPayPassword(Long uid){
        //1.确认是哪个用户设置支付密码的回调
        userInfoService.updateHostingPayPassword(uid);
        return "支付密码设置成功";
    }*/
    /**
     * 绑定邮箱
     */
  /*  @RequestMapping("bindEmail")
    public String bindEmail(Model model){

    }*/
}
